#include "customerthread.h"
#include <QDebug>
#include "dataqueue.h"
extern QMutex  myMutex;

CustomerThread::CustomerThread(int index, QWaitCondition *hasSpaceCond, QWaitCondition *hasDataCond)
{
    this->index = index;
    this->hasSpaceCond = hasSpaceCond;
    this->hasDataCond = hasDataCond;
}

void CustomerThread::run()
{
    QMutex& mutex = DataQueue::getInstance().getQMutex();
    while (!stop) {
        QString data = DataQueue::getInstance().getData();
        this->hasSpaceCond->wakeAll();//唤醒所有生产者，开始工作
        if(data == ""){
            qDebug()<< "No."<<index<<QStringLiteral("缓冲区中没有数据 ,等待生产No.")<< index;
            this->hasDataCond->wait(&mutex);
            continue;
        }
        qDebug()<< "Customer No."<<index<<data;
    }
}
